Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/data

Package Overview
Dependencies
Maintainers
25
Versions
221
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/data

Data module for WordPress.

  • 8.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132K
increased by0.76%
Maintainers
25
Weekly downloads
 
Created

What is @wordpress/data?

@wordpress/data is a state management library specifically designed for WordPress applications. It provides a centralized way to manage and share state across different parts of a WordPress application, leveraging the Redux pattern.

What are @wordpress/data's main functionalities?

Store Registration

This feature allows you to register a new store with a reducer, actions, and selectors. The store can then be used to manage state within your application.

const { registerStore } = wp.data;
const myStore = registerStore('my-store', {
  reducer: (state = {}, action) => {
    switch (action.type) {
      case 'SET_VALUE':
        return { ...state, value: action.value };
      default:
        return state;
    }
  },
  actions: {
    setValue(value) {
      return { type: 'SET_VALUE', value };
    }
  },
  selectors: {
    getValue(state) {
      return state.value;
    }
  }
});

Dispatching Actions

This feature allows you to dispatch actions to update the state in a registered store. In this example, the 'setValue' action is dispatched to update the state with a new value.

const { dispatch } = wp.data;
dispatch('my-store').setValue('new value');

Selecting State

This feature allows you to select and retrieve state from a registered store. In this example, the 'getValue' selector is used to get the current value from the store.

const { select } = wp.data;
const value = select('my-store').getValue();
console.log(value);

Resolving Selectors

This feature allows you to resolve selectors that might involve asynchronous operations. In this example, the 'getValue' selector is resolved and the value is logged once it is available.

const { resolveSelect } = wp.data;
resolveSelect('my-store').getValue().then(value => {
  console.log(value);
});

Other packages similar to @wordpress/data

Keywords

FAQs

Package last updated on 15 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc